<template>
  <el-tag v-if="list.length" class="timelimit">
    {{ `${startTime} ~ ${endTime}` }}
  </el-tag>
</template>
<script>
import { parseTime } from '@/utils/index'
export default {
  name: 'TimeLimit',
  props: {
    queryType: {
      type: Number,
      default: 0
    },
    list: {
      type: Array,
      default: () => {
        return []
      }
    },
    timeTypeMap: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {}
  },
  computed: {
    startTime() {
      if (this.list.length) {
        return parseTime(this.list[this.list.length - 1].time, this.timeTypeMap[this.queryType])
      } else {
        return null
      }
    },
    endTime() {
      if (this.list.length) {
        if (this.queryType === 1) {
          const weeklimit = parseTime(this.list[0].time, this.timeTypeMap[this.queryType], 1)
          return weeklimit.substring(weeklimit.indexOf('~') + 1)
        } else {
          return parseTime(this.list[0].time, this.timeTypeMap[this.queryType])
        }
      } else {
        return null
      }
    }
  }
}
</script>
